package com.dycx.common.rabbitmq.provider;

import com.dycx.common.rabbitmq.RabbitMqConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

/**
 * 消息发送实现类
 *
 * @author LiuHui
 * @since 2023-05-16
 **/
@Slf4j
@Component
public class PaymentMqMessage {
    @Autowired
    private static RabbitTemplate rabbitTemplate;

    @Autowired
    private static RabbitMqConfig rabbitMqConfig;

    public PaymentMqMessage(@Qualifier(value = "rabbitTemplate") RabbitTemplate rabbitTemplate, RabbitMqConfig rabbitMqConfig) {
        PaymentMqMessage.rabbitTemplate = rabbitTemplate;
        PaymentMqMessage.rabbitMqConfig = rabbitMqConfig;
    }

    public static void sendCreatePaymentMsg(String content) {
        try {
            log.info("============================================>发送创建支付请求:{}", content);
            rabbitTemplate.convertAndSend(rabbitMqConfig.getPaymentExchange(),
                    rabbitMqConfig.getPaymentCreateRouting(), content);
        } catch (Exception e) {
            log.error("发送创建支付请求失败,msg,e:{},{}", content, e);
        }
    }

}
